package com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.childfragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.qingyiapp.R;
import com.example.qingyiapp.service.entify.FindChoicenessOneBean;
import com.example.qingyiapp.service.entify.FindChoicenessTwoBean;
import com.example.qingyiapp.service.entify.FindSynamicBean;
import com.example.qingyiapp.service.entify.FindTJBean;
import com.example.qingyiapp.service.entify.FindWaitYouBean;
import com.example.qingyiapp.service.presenter.PersenterMannaer;
import com.example.qingyiapp.service.view.IFindView;
import com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.adapter.FindSquareDynamicRecyclerAdapter;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Creadted by Met·Wang on 2019/9/27 14:15
 * Describe: NullPointerException Write
 */
public class dynamic_fragment extends Fragment implements IFindView {


    Unbinder unbinder;
    PersenterMannaer iRequestPersenter;


    ArrayList<FindSynamicBean.DataBean> list;
    FindSquareDynamicRecyclerAdapter adapter;
    @BindView(R.id.find_squre_fragment2)
    XRecyclerView findSqureFragment;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_find_dynamic, container, false);


        unbinder = ButterKnife.bind(this, inflate);

        iRequestPersenter = new PersenterMannaer(getContext(), "http://www.iqingyi.com/");
        iRequestPersenter.onCreate();
        iRequestPersenter.attchview2(this);
        iRequestPersenter.getFindSynamicBean();


        list = new ArrayList<>();
        adapter = new FindSquareDynamicRecyclerAdapter(list, getContext());
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        findSqureFragment.setLayoutManager(manager);
        findSqureFragment.setAdapter(adapter);


        return inflate;
    }

    @Override
    public void getjsonstring(FindTJBean s) {

    }

    @Override
    public void getChoicenessOneBean(FindChoicenessOneBean bean) {

    }

    @Override
    public void getChoicenessTwoBean(FindChoicenessTwoBean bean) {

    }

    @Override
    public void getFindWaitYou(FindWaitYouBean bean) {

    }

    @Override
    public void getFindSynamic(FindSynamicBean bean) {
        List<FindSynamicBean.DataBean> data = bean.getData();
        for (int i = 0; i < data.size(); i++) {
            list.add(data.get(i));
        }
        adapter.notifyDataSetChanged();
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


}
